package cn.net.yugu.doraemon.redis;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;

/**
 * @description:
 * @author: wanghongli
 * @create: 2022-07-18 00:05:50
 */
public class RedisClientWrapper implements InitializingBean {
     private final RedisTemplate<String, String> redisTemplate;
     private final RedisConnectionFactory redisConnectionFactory;

    public RedisClientWrapper(RedisTemplate<String, String> redisTemplate, RedisConnectionFactory redisConnectionFactory) {
        this.redisTemplate = redisTemplate;
        this.redisConnectionFactory = redisConnectionFactory;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        if(redisConnectionFactory instanceof LettuceConnectionFactory){
            LettuceConnectionFactory c=(LettuceConnectionFactory)redisConnectionFactory;
            c.setValidateConnection(true);
        }
        RedisUtils.setTemplate(redisTemplate);
    }
}
